package graphics.rasterizing.shading;

import static util.MatrixOperationsF.ar;
import graphics.rasterizing.model.Triangle;

import java.util.Random;

/**
 * Shader that gives each triangle a random color. the shader checks if the
 * current triangle is the same as the last one.
 */
public class RandomColorShader implements Shader {
	private final Random random = new Random();
	private float[] c;
	Triangle last = null;

	@Override
	public float[] shade(float alpha, float beta, float gamma, Triangle tri) {
		if (new_tri(tri)) {
			c = ar(random.nextFloat(), random.nextFloat(), random.nextFloat());
			last = tri;
		}
		return c;

	}

	private boolean new_tri(Triangle tri) {
		return tri != last;
	}

}
